package com.qianheng.kit.base.arithmetic;

import org.springframework.stereotype.Component;

@Component
public class 面试题 {

    /**
     * 字符串反转, 并转大写. 如果遇到"ali"就保持原样
     * @param s
     * @return
     */
    String reverse(String s) {
        char[] ali = new char[]{'a', 'l', 'i'};

        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length / 2 + 1; i++) {
            char c = chars[i];
            chars[i] = Character.toUpperCase(chars[chars.length - i - 1]);
            chars[chars.length - i - 1] = Character.toUpperCase(c);
        }

        for (int i = 0; i < chars.length - 2; i++) {
            if (chars[i] == 'I' && chars[i + 1] == 'L' && chars[i + 2] == 'A') {
                chars[i] = 'a';
                chars[i + 1] = 'l';
                chars[i + 2] = 'i';
                i += 2;
            }
        }
        return new String(chars);
    }
}
